from dao.contact_dao import ContactDAO


class ContactService:
    def __init__(self):
        self.contact_dao = ContactDAO()




    def get_contact_by_wechat_name(self, wechat_name):
        "根据微信名和备注名查询微信联系人的信息"
        contacts = self.contact_dao.get_users_by_wechat_name(wechat_name)

        # 转换为字典格式
        contacts_data = []
        for contact in contacts:
            contact_dict = {
                'id': contact.id,
                'wechat_name': contact.wechat_name,
                'remark_name': contact.remark_name,
                'wechat_id': contact.wechat_id,
                'user_type': contact.user_type,
                'avatar_url': contact.avatar_url,
                'signature': contact.signature,
                'description': contact.description,
                'account': contact.account
            }
            contacts_data.append(contact_dict)

        data = {
            "contacts": contacts_data,
            "count": len(contacts_data)
        }
        return data